package com.example.wuqujingdianphone.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.wuqujingdianphone.R;
import com.example.wuqujingdianphone.adapter.AudioMoreAdapter;
import com.example.wuqujingdianphone.adapter.VideoMoreAdapter;
import com.example.wuqujingdianphone.api.ApiConfig;
import com.example.wuqujingdianphone.base.BaseActivity;
import com.example.wuqujingdianphone.bean.AudioMoreBean;
import com.example.wuqujingdianphone.bean.TingshuHomeBean;
import com.example.wuqujingdianphone.bean.VideoMoreBean;
import com.example.wuqujingdianphone.utils.GsonUtil;
import com.example.wuqujingdianphone.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 视频列表
 */
public class AudioMoreActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.title)
    TextView mTitle;
    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerView;
    private ArrayList<AudioMoreBean> listBeans = new ArrayList<>();
    private String title = "";
    private String id = "";
    private AudioMoreAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_list);
        ButterKnife.bind(this);
        title = getIntent().getStringExtra("title");
        id = getIntent().getStringExtra("id");
        mTitle.setText(title);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initView();
        initData();
    }

    private void initView() {
        mRecyclerView.setLayoutManager(new GridLayoutManager(getApplicationContext(), 3));
        mAdapter = new AudioMoreAdapter(getApplicationContext(), null);
        mAdapter.openLoadAnimation();
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ArrayList<AudioMoreBean.ListBean.ModelBean> muluList = new ArrayList<>();
                for (int i = 0; i < listBeans.get(position).getList().size(); i++) {
                    muluList.addAll(listBeans.get(position).getList().get(i).getModel());
                }
                Bundle bundle = new Bundle();
                bundle.putParcelableArrayList("listFrom", muluList);
                bundle.putString("title", listBeans.get(position).getYinpinname());
                bundle.putString("bac", "http://www.wenqujingdian.com"+listBeans.get(position).getSpic());
                Intent intent = new Intent(getApplicationContext(), AudioList11Activity.class);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }

    private void initData() {
        showLoading(this);
        OkGo.<String>get(ApiConfig.APP_URL + "index.php/jiekou/getAudioByClassId/cid/" + id)
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String ds = response.body();
                        cancelLoading();
                        listBeans.clear();
                        listBeans = GsonUtil.getObject1List(response.body(), AudioMoreBean.class);
                        mAdapter.setNewData(listBeans);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        cancelLoading();
                        ToastUtil.show("加载失败");
                    }
                });
    }


}
